package com.emuporium.gymrat.server.routine;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.emuporium.gymrat.server.data.Entry;
import com.emuporium.gymrat.server.data.ExerciseDB;
import com.emuporium.gymrat.server.data.RoutineDB;
import com.emuporium.gymrat.server.data.User;
import com.emuporium.gymrat.server.data.UserDB;
import com.emuporium.gymrat.server.data.Variation;

@SuppressWarnings("serial")
public class RoutineEditEntryServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int entryId = new Integer(request.getParameter("entryid"));
		User user = UserDB.selectUser(request.getRemoteUser());
		Entry entry = RoutineDB.selectEntry(entryId);
		ArrayList<Variation> variations = new ArrayList<Variation>();
		variations = ExerciseDB.selectVariations(entry.getExerciseId(), user
				.getId());
		int routineId = new Integer(request.getParameter("routineid"));
		request.setAttribute("entry", entry);
		request.setAttribute("variations", variations);
		request.setAttribute("routineid", routineId);
		String url = "/routine/editEntry.jsp";
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher(url);
		dispatcher.forward(request, response);

	}
}
